const baseurl = "http://192.168.4.18";
function http({
    url,
    success
}){
    wx.request({
        url: baseurl+url,
        data: {},
        header: {'content-type':'application/json'},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (res)=>{
            success(res)
        },
        fail: ()=>{},
        complete: ()=>{}
    });
}

function getHttpCart({
    success
}){
    http({
        url:":8000/cart",
        success:res=>{
            success(res)
        }
    })
}

function getHttpCat({
    offset=0,
    success
}){
    http({
        url:`top/playlist?cat=华语&limit=15&offset=${offset}`,
        success:res=>{
            success(res)
        }
    })
}

function changeNum(num){
    let arr = [];
    for(let i = 0;i<5;i++){
        if (num>2){
            arr.push(2)
        }else if(num>0){
            arr.push(Number(num.toFixed(1)))
        }else{
            arr.push(0)
        }
        num = num-2;
    }
    return arr;
}

module.exports = {
    getHttpCart,
    http,
    getHttpCat,
    changeNum
}